package com.yizhang.annotation.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @Author: yi.zhang
 * @CreateTime: 2025-06-11 13:18:21
 * @Description: aop通知
 */
@Aspect
@Component
public class MyAdvice {

    @Pointcut(value = "execution(* com.yizhang.annotation.entity..*.*(..))")
    public void pointCut() {

    }

    @Before(value = "pointCut()")
    public void before() {
        System.out.println("前置通知====================");
    }

    @AfterReturning(value = "pointCut()")
    public void afterReturning() {
        System.out.println("后置通知====================");
    }

    @Around(value = "pointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕前通知====================");
        Object result = joinPoint.proceed();
        System.out.println("环绕后通知====================");
        return result;
    }

    @AfterThrowing(value = "pointCut()", throwing = "e")
    public void afterThrowing(Throwable e) {
        System.out.println("异常通知====================");
        System.out.println("异常：" + e.getMessage());
    }

    @After(value = "pointCut()")
    public void after() {
        System.out.println("最终通知====================");
    }
}
